package com.ruoyi.system.service.impl;
import com.ruoyi.system.domain.vo.InspectionPlanTaskCountVO;
import com.ruoyi.system.domain.vo.InspectionPlanTaskVO;
import com.ruoyi.system.entity.InspectionPlanTask;
import com.ruoyi.system.mapper.InspectionPlanTaskMapper;
import com.ruoyi.system.service.InspectionPlanTaskService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 计划任务表(InspectionPlanTask)表服务实现类
 * @since 2022-11-28 17:55:24
 */
@Service("inspectionPlanTaskService")
public class InspectionPlanTaskServiceImpl implements InspectionPlanTaskService {
    @Resource
    private InspectionPlanTaskMapper inspectionPlanTaskMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public InspectionPlanTask queryById(Integer id) {
        return this.inspectionPlanTaskMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param inspectionPlanTask 筛选条件
     * @return 查询结果
     */
    @Override
    public List<InspectionPlanTask> queryByPage(InspectionPlanTask inspectionPlanTask) {
        return inspectionPlanTaskMapper.queryAllByLimit(inspectionPlanTask);
    }

    /**
     * 新增数据
     *
     * @param inspectionPlanTask 实例对象
     * @return 实例对象
     */
    @Override
    public InspectionPlanTask insert(InspectionPlanTask inspectionPlanTask) {
        if (null == inspectionPlanTask.getCreateTime()) {
            inspectionPlanTask.setCreateTime(LocalDateTime.now());
        }
        this.inspectionPlanTaskMapper.insert(inspectionPlanTask);
        return inspectionPlanTask;
    }

    /**
     * 修改数据
     *
     * @param inspectionPlanTask 实例对象
     * @return 实例对象
     */
    @Override
    public InspectionPlanTask update(InspectionPlanTask inspectionPlanTask) {
        this.inspectionPlanTaskMapper.update(inspectionPlanTask);
        return this.queryById(inspectionPlanTask.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.inspectionPlanTaskMapper.deleteById(id) > 0;
    }

    @Override
    public InspectionPlanTask queryByPlanId(Integer id) {
        return inspectionPlanTaskMapper.queryByPlanId(id);
    }

    @Override
    public List<InspectionPlanTaskVO> getCountAll(Integer id) {
        return inspectionPlanTaskMapper.getCountAll(id);
    }

    @Override
    public void updateStateByRouteId(Integer id) {
        inspectionPlanTaskMapper.updateStateByRouteId(id);
    }

    @Override
    public int getZCxj() {
        return inspectionPlanTaskMapper.getZCxj();
    }

    @Override
    public int getCSxj() {
        return inspectionPlanTaskMapper.getCSxj();
    }

    @Override
    public int getZgCount() {
        return inspectionPlanTaskMapper.getZgCount();
    }

    @Override
    public int getPcCount() {
        return inspectionPlanTaskMapper.getPcCount();
    }

    @Override
    public int getWclCount() {
        return inspectionPlanTaskMapper.getWclCount();
    }

    @Override
    public int getBflCount() {
        return inspectionPlanTaskMapper.getBflCount();
    }

    @Override
    public int getCountRouteTo(String name) {
        return inspectionPlanTaskMapper.getCountRouteTo(name);
    }

    @Override
    public List<InspectionPlanTaskCountVO> getAllRouteTo() {
        return inspectionPlanTaskMapper.getAllRouteTo();
    }

    @Override
    public List<InspectionPlanTask> getAllCountTimeTo(String startTime, String endTime) {
        return inspectionPlanTaskMapper.getAllCountTimeTo(startTime,endTime);
    }


    @Override
    public List<InspectionPlanTaskCountVO> getAllTypeCount() {
        return inspectionPlanTaskMapper.getAllTypeCount();
    }

    @Override
    public int getWwcCount() {
        return inspectionPlanTaskMapper.getWwcCount();
    }

    @Override
    public int getYwcCount() {
        return inspectionPlanTaskMapper.getYwcCount();
    }

    @Override
    public int getYcsCount() {
        return inspectionPlanTaskMapper.getYcsCount();
    }

    @Override
    public List<InspectionPlanTaskCountVO> getTypeNameCount(String name) {
        return inspectionPlanTaskMapper.getTypeNameCount(name);
    }

    @Override
    public List<InspectionPlanTaskCountVO> getAllDangerList() {
        return inspectionPlanTaskMapper.getAllDangerList();
    }

    @Override
    public List<InspectionPlanTaskCountVO> getCountArea() {
        return inspectionPlanTaskMapper.getCountArea();
    }

    @Override
    public List<InspectionPlanTaskCountVO> getCountDept() {
        return inspectionPlanTaskMapper.getCountDept();
    }

    @Override
    public Map<String, Object> countSize() {
        Map<String, Object> map = new HashMap<>();
        InspectionPlanTask w = new InspectionPlanTask();
        w.setPlanTaskState("已完成");
        long wl = inspectionPlanTaskMapper.count(w);
        InspectionPlanTask c = new InspectionPlanTask();
        c.setPlanTaskState("已超时");
        long cl = inspectionPlanTaskMapper.count(c);
        long all = inspectionPlanTaskMapper.count(new InspectionPlanTask());
        map.put("total",all);
        map.put("timeout",cl);
        map.put("complete",all / wl * 100);
        return map;
    }

}
